home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Atari Compendium
/
The Atari Compendium (Toad Computers) (1994).iso
/
files
/
umich
/
utils
/
nroff~06.zoo
/
main.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-07-16
|
25KB
|
1,142 lines
static char *rcsid_main_c="$Id: main.c,v 1.2 1992/07/16 10:38:32 rosenkra Exp $";
/*
* $Log: main.c,v $
* Revision 1.2 1992/07/16 10:38:32 rosenkra
* port to gcc, add tm,ie,el
*
*/
#include "config.h"
/*
* main.c - main for nroff word processor
*
* similar to Unix(tm) nroff or RSX-11M RNO. adaptation of text processor
* given in "Software Tools", Kernighan and Plauger.
*
* adapted for atariST/TOS by Bill Rosenkranz 11/89
* net: rosenkra@convex.com
* CIS: 71460,17
* GENIE: W.ROSENKRANZ
*
* original author:
*
* Stephen L. Browning
* 5723 North Parker Avenue
* Indianapolis, Indiana 46220
*
* history:
*
* - Originally written in BDS C;
* - Adapted for standard C by W. N. Paul
* - Heavily hacked up to conform to "real" nroff by Bill Rosenkranz
*/
#define NRO_MAIN /* to define globals in nro.h */
#include <stdio.h>
#ifdef GEMDOS
# ifdef __GNUC__
# include <types.h>
# include <time.h>
# include <stdlib.h>
# include <string.h>
# include <unistd.h>
# else
# include <sys\types.h>
# include <sys\time.h>
# endif
#else
# include <sys/types.h>
# include <sys/time.h>
#endif
#include "nroff.h"
/*------------------------------*/
/* main */
/*------------------------------*/
void main (argc, argv)
int argc;
char *argv[];
{
REGISTER int i;
int swflg;
int ifp = 0;
char *ptmp;
#ifndef GEMDOS
char *pterm;
char capability[100];
char *pcap;
char *ps;
#endif
/*
* set up initial flags and file descriptors
*/
swflg = FALSE;
ignoring = FALSE;
hold_screen = FALSE;
debugging = FALSE;
stepping = FALSE;
mc_ing = FALSE;
out_stream = stdout;
err_stream = stderr;
dbg_stream = stderr;
/*
* this is for tmp files, if ever needed. it SHOULD start
* out without the trailing slash. if not in env, use default
*/
if (ptmp = getenv ("TMPDIR"))
strcpy (tmpdir, ptmp);
else
strcpy (tmpdir, ".");
/*
* initialize structures (defaults)
*/
init ();
ex_macro[0] = '\0';
ex_macro[1] = '\0';
ex_macro[2] = '\0';
ex_macro[3] = '\0';
ex_macro[4] = '\0';
/*
* parse cmdline flags
*/
for (i = 1; i < argc; ++i)
{
if (*argv[i] == '-' || *argv[i] == '+')
{
if (pswitch (argv[i], &swflg) == ERR)
err_exit (-1);
}
}
/*
* handle terminal for \fB, \fI
*/
#ifdef GEMDOS
if (ansi_escapes)
{
/*
* this is new a p4. i checked a lot of termcap entries,
* and found that "ESC [ n m" is common to turn on certain
* capabilities (like standout and underline, but that
* "ESC [ m" was more common than "ESC [ 0 m" to turn them
* off. i perfer the "0" but that does not appear to work
* with vt100's.
*
* vt100 supports standout (so) which i map to standout,
* bold (md) which i map to bold, rev video (standout), and
* us (underline) which i map to italic. the others will
* do nothing. there is currently no way to get rev video
* and small character escape sequences out of nroff.
* it only supports R, B, I, and S. both ms and man have
* a ".SM t" macro for small text, perhaps this could be
* added to nroff itself. .SM macro changes point size,
* which is normally ignored by nroff anyway. it is for
* troff.
*
* these codes work with manpager...
*/
strcpy (s_bold, "\33[1m"); /* \fB bold font */
strcpy (e_bold, "\33[m");
strcpy (s_italic, "\33[4m"); /* \fI italic/underline font */
strcpy (e_italic, "\33[m");
strcpy (s_special, "\33[9m"); /* \fS special/math font */
strcpy (e_special, "\33[m");
strcpy (s_standout, "\33[7m"); /* standout/rev video font */
strcpy (e_standout, "\33[m");
strcpy (s_small, "\33[8m"); /* small font */
strcpy (e_small, "\33[m");
strcpy (e_all, "\33[m"); /* \fR normal font */
}
else
{
strcpy (s_standout, "\33p"); /* atari/TOS is easy... */
strcpy (e_standout, "\33q");
strcpy (s_bold, "\33p"); /* atari/TOS is easy... */
strcpy (e_bold, "\33q");
strcpy (s_italic, "\33p");
strcpy (e_italic, "\33q");
}
#else
s_standout[0] = '\0';
e_standout[0] = '\0';
s_bold[0] = '\0';
e_bold[0] = '\0';
s_italic[0] = '\0';
e_italic[0] = '\0';
if ((pterm = getenv ("TERM")) /* it must exist first... */
&& (tgetent (termcap, pterm) == 1)) /* ...so we fill buffer */
{
/*
* we currently use standout mode for all weirdness
* lile BOLD, italic, etc.
*/
pcap = capability;
if (ps = tgetstr ("so", &pcap))
{
/*
* sun has padding in here. this is NOT portable.
* better to use tputs() to strip it...
*/
while (*ps && *ps != 0x1b) ps++;
strcpy (s_standout, ps);
strcpy (s_bold, ps);
strcpy (s_italic, ps);
}
if (ps = tgetstr ("se", &pcap))
{
while (*ps && *ps != 0x1b) ps++;
strcpy (e_standout, ps);
strcpy (e_bold, ps);
strcpy (e_italic, ps);
}
}
#endif
/*
* loop on files
*/
for (i = 1; i < argc; ++i)
{
if (*argv[i] != '-' && *argv[i] != '+')
{
/*
* open this file...
*/
if ((sofile[0] = fopen (argv[i], "r")) == NULL_FPTR)
{
fprintf (err_stream,
"***%s: unable to open file %s\n",
myname, argv[i]);
err_exit (-1);
}
else
{
/*
* do it for this file...
*/
ifp = 1;
profile ();
fclose (sofile[0]);
}
}
else if (*argv[i] == '-' && *(argv[i]+1) == 0)
{
/*
* - means read stdin (anywhere in file list)
*/
sofile[0] = stdin;
ifp = 1;
profile ();
}
}
/*
* if no files, usage (should really use stdin...)
*/
#ifdef USE_STDIN
if (ifp == 0)
{
sofile[0] = stdin;
ifp = 1;
profile ();
}
#else
if ((ifp == 0 && swflg == FALSE) || argc <= 1)
{
usage ();
err_exit (-1);
}
#endif
/*
* execute any exit macro (defined with .em)
*/
if (ex_macro[1])
{
char ibuf[MAXLINE];
/*
* comand will push any macro on the pb buffer so getlin
* can do its thing
*/
ex_macro[0] = dc.cmdchr;
comand (ex_macro);
while (getlin (ibuf, NULL_FPTR) != EOF)
{
/*
* if line is a command or text
*/
if (ibuf[0] == dc.cmdchr)
{
comand (ibuf);
}
else
{
/*
* this is a text line. first see if
* first char is space. if it is, break
* line.
*/
if (ibuf[0] == ' ')
robrk ();
text (ibuf);
}
}
}
/*
* now finish last page (if ex_macro does .ex, we never get here)
*/
if (pg.lineno > 0)
space (HUGE);
/*
* normal exit. this will fflush/fclose streams...
*/
err_exit (0);
/*NOTREACHED*/
}
/*------------------------------*/
/* usage */
/*------------------------------*/
void usage ()
{
/*
* note: -l may not work correctly
*/
fprintf (stderr, "Usage: %s [options] file [...]\n", myname);
fprintf (stderr, "Options: -a no font changes\n");
fprintf (stderr, " -T<name> terminal (device) name\n");
fprintf (stderr, " (currently set for ANSI/vt100 escapes)\n");
fprintf (stderr, " -b backspace\n");
fprintf (stderr, " -d debug mode (stderr or err log if -e first)\n");
fprintf (stderr, " -debug debug mode (nroff.dbg)\n");
#ifdef GEMDOS
fprintf (stderr, " -h hold screen before desktop\n");
#endif
/*!!! fprintf (stderr, " -l output to printer\n");*/
fprintf (stderr, " -m<name> macro file (e.g. -man)\n");
fprintf (stderr, " -e<file> error log file (stderr is default)\n");
fprintf (stderr, " -po<n> page offset\n");
fprintf (stderr, " -pn<n> initial page number\n");
fprintf (stderr, " -pl<n> page length\n");
fprintf (stderr, " -s step through pages\n");
fprintf (stderr, " -v print version only\n");
fprintf (stderr, " +<